/**
 * @author https://vue-admin-beautiful.com （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'
import PermissionType from '@/utils/PermissionType'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/weixin',
    component: () => import('@/views/weixin'),
    hidden: true
  },
  {
    path: '/wxcode',
    component: () => import('@/views/wxcode'),
    hidden: true
  },
  {
    path: '/',
    name: 'index',
    component: () => import('@/views/index/index'),
    hidden: true,
  },

  /*通过点击按钮打开 tabsBar 快捷导航*/
  {
    path: '/publicnav',
    component: Layout,
    redirect: 'noRedirect',
    name: 'PublicNav',
    hidden: true,
    children: [
      {
        path: 'studentview',
        name: 'PublicNav_studentview',
        component: () => import('@/views/basedata/student/studentview'),
        meta: { title: '学生查看', icon: 'user', permissions: [PermissionType.baseData_student]  },
      },
    ],
  },
]

export const asyncRoutes = [
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/index',
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Index',
  //       component: () => import('@/views/index/index'),
  //       meta: {
  //         title: '首页',
  //         icon: 'home',
  //         affix: true,
  //       },
  //     },
  //   ],
  // },
  {
    path: '/sys',
    component: Layout,
    redirect: 'noRedirect',
    name: 'SysManagement',
    meta: { title: '系统管理', icon: 'tools', permissions: [PermissionType.sysAdmin] },
    children: [
      {
        path: 'org',
        name: 'sys_org_org',
        component: () => import('@/views/sys/org/org'),
        meta: { title: '组织架构', icon: 'cog' },
      },
      {
        path: 'orguser',
        name: 'sys_org_orguser',
        component: () => import('@/views/sys/org/orguser'),
        meta: { title: '组织用户', icon: 'cog' },
      },
      {
        path: 'user',
        name: 'sys_user_user',
        component: () => import('@/views/sys/user/user'),
        meta: { title: '用户管理', icon: 'user' },
      },
      {
        path: 'role',
        name: 'sys_role_role',
        component: () => import('@/views/sys/role/role'),
        meta: { title: '角色管理', icon: 'user-lock' },
      },
    ],
  },

  {
    path: '/basedata',
    component: Layout,
    redirect: 'noRedirect',
    name: 'BaseData',
    meta: { title: '数据管理', icon: 'database', permissions: [PermissionType.baseData]   },
    children: [
      {
        path: 'class',
        name: 'basedata_class_class',
        component: () => import('@/views/basedata/class/class'),
        meta: { title: '班级管理', icon: 'chalkboard-teacher', permissions: [PermissionType.baseData_class]  },
      },
      {
        path: 'student',
        name: 'basedata_student_student',
        component: () => import('@/views/basedata/student/student'),
        meta: { title: '学生管理', icon: 'user-friends', permissions: [PermissionType.baseData_student]  },
      },
    ],
  },

  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
